package view.items;

import java.awt.Color;
import java.awt.Insets;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;

import model.Call;

import controller.Controller;

public class PanelBottomChat extends JPanel {
	
	

	private Controller controller;
	private JTextArea textChat;
	private JTextArea affichage;
	private JButton buttonSend;
	private JScrollPane scrollAffichage;
	private JScrollPane scrollSaisie;

	public PanelBottomChat(Controller controller){
		this.setBackground(Color.white);
		JLabel label = new JLabel("chat here");
		this.add(label);
		this.setLayout(null);
		this.controller = controller;
		
		
		
		
		
		textChat = new JTextArea();
		scrollSaisie = new JScrollPane(textChat);
		scrollSaisie.setBounds(0, 168, 420, 50);
		
		buttonSend = new JButton("send");
		buttonSend.setBounds(420, 168, 50, 49);
		buttonSend.setMargin(new Insets(0, 0, 0, 0));
		buttonSend.setActionCommand("buttonSendChat");
		buttonSend.addActionListener(controller);
		
		affichage = new JTextArea();
		affichage.setEditable(false);
		affichage.setLineWrap(true);//pour retour a la ligne
		affichage.setWrapStyleWord(true);//pour que les mots ne soient pas coupés
		scrollAffichage = new JScrollPane(affichage);
		scrollAffichage.setBounds(0, 0, 470, 159);
		scrollAffichage.setFocusable(true);
		
		this.add(buttonSend);
		this.add(scrollSaisie);
		this.add(scrollAffichage);
		this.refresh();
	}

	public void refresh() {
		Call selected = this.controller.getModel().getSelectedCall();
		if(selected != null){
		String allChatMsg = selected.getMessageFromCall();
		affichage.setText(allChatMsg);
		affichage.setForeground(Color.black);
		buttonSend.setVisible(true);
		scrollAffichage.setVisible(true);
		scrollSaisie.setVisible(true);
		}
		else{
			buttonSend.setVisible(false);
			scrollAffichage.setVisible(false);
			scrollSaisie.setVisible(false);
		}
		this.repaint();
		this.revalidate();
		
	}

	public JTextArea getTextChat() {
		return textChat;
	}
	
	
}
